/*
 * DxfINSERT.java
 *
 * Created on 6 de Dezembro de 2007, 10:29
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package importadorDXF;

import mathematics.Point3D;

/**
 *
 * @author rafaelbuck
 */
public class DxfINSERT extends DxfEntity
    implements DxfEntityCollector
{

    public boolean setGroup(short grpNr, float fval)
    {
        switch(grpNr)
        {
        case 10: // '\n'
        case 20: // '\024'
        case 30: // '\036'
            setCoord(insertPoint, grpNr / 10, fval);
            return true;

        case 41: // ')'
            scaleX = fval;
            return true;

        case 42: // '*'
            scaleY = fval;
            return true;

        case 43: // '+'
            scaleZ = fval;
            return true;

        case 44: // ','
            colDist = fval;
            return true;

        case 45: // '-'
            rowDist = fval;
            return true;

        case 50: // '2'
            rotAngle = (float)(((double)fval / 180D) * 3.1415926535897931D);
            return true;
        }
        return super.setGroup(grpNr, fval);
    }

    public boolean setGroup(short grpNr, int ival)
    {
        switch(grpNr)
        {
        case 66: // 'B'
            attribFollows = ival != 0;
            if(attribFollows)
                attribSet = new DxfEntitySet();
            return true;

        case 70: // 'F'
            nrCols = ival;
            return true;

        case 71: // 'G'
            nrRows = ival;
            return true;
        }
        return super.setGroup(grpNr, ival);
    }

    public boolean setGroup(short grpNr, String str)
    {
        switch(grpNr)
        {
        case 2: // '\002'
            blockName = str;
            return true;
        }
        return super.setGroup(grpNr, str);
    }

    public void convert(DxfConverter converter, DxfFile dxf, Object collector)
    {
        converter.convert(this, dxf, collector);
    }

    public final Point3D getInsertPoint()
    {
        return insertPoint;
    }

    public final String getBlockName()
    {
        return blockName;
    }

    public final float getScaleX()
    {
        return scaleX;
    }

    public final float getScaleY()
    {
        return scaleY;
    }

    public final float getScaleZ()
    {
        return scaleZ;
    }

    public final float getRotation()
    {
        return rotAngle;
    }

    public final int getRows()
    {
        return nrRows;
    }

    public final int getColumns()
    {
        return nrCols;
    }

    public final float getRowDistance()
    {
        return rowDist;
    }

    public final float getColumnDistance()
    {
        return colDist;
    }

    public final boolean attributesFollowing()
    {
        return attribFollows;
    }

    public boolean addEntity(DxfEntity entity)
        throws DxfException
    {
        if(attribFollows && (entity instanceof DxfATTRIB))
        {
            attribSet.addEntity(entity);
            return true;
        } else
        {
            return false;
        }
    }

    public DxfEntityCollector getEntityCollector()
    {
        return attribFollows ? this : null;
    }

    public DxfEntitySet getAttributes()
    {
        return attribSet;
    }
    
    /** Creates a new instance of DxfINSERT */
    public DxfINSERT()
    {
        insertPoint = new Point3D();
        scaleX = 1.0F;
        scaleY = 1.0F;
        scaleZ = 1.0F;
        nrRows = 1;
        nrCols = 1;
        attribFollows = false;
    }

    protected Point3D insertPoint;
    protected String blockName;
    protected float scaleX;
    protected float scaleY;
    protected float scaleZ;
    protected float rotAngle;
    protected int nrRows;
    protected int nrCols;
    protected float rowDist;
    protected float colDist;
    protected boolean attribFollows;
    protected DxfEntitySet attribSet;
}